(function() {
    $(document).ready(function() {

        $(".box-remove").click(function(e) {
            var box;

            box = $(this).parents(".box");
            box.fadeOut(300, function() {
                return $(this).remove();
            });
            return e.preventDefault();
        });

        $('.comments').editable({
            showbuttons: true,
            url: window.location.protocol+'//'+window.location.hostname+'/backend/images/add_comment'
        });

        $('.btn.delete').click(function(){
            var row, id;

            row = $(this).parents("tr");
            id = row.attr("class").substring(4);
            $.ajax({
                type: "POST",
                url: window.location.protocol+'//'+window.location.hostname+'/backend/images/delete',
                data: "pk="+id,
                async: true,
                dataType: "json",
                success: function(responce, textStatus, XMLHttpRequest)
                {
                    if(responce.success){
                        row.fadeOut(300, function() {
                            return $(this).remove();
                        });
                    }else{
                        alert('error');
                    }
                },
                error: function(request, textStatus, errorThrown)
                {
                    alert('error refreshing the session');
                }
            });

        });

    });
    
}).call(this);


